import Vue from 'vue'
import axios from 'axios';
Vue.prototype.$axios = axios;

axios.defaults.headers.common['Content-Type'] = 'application/json';

//let basedomain = 'http://192.168.1.130:9000';
let basedomain = 'http://192.168.1.182:9001';
//let basedomain = 'https://atompai.com';

let base = basedomain+'/api/v1.0',// 192.168.1.130:9000 yuru  107 peilei
	baseNotLog=basedomain, //未登录接口
	baseAuth=basedomain+'/auth';//用户等接口

// 超时时间
// axios.defaults.timeout = 500000;
//axios管理请求头
axios.interceptors.request.use(
	config => {
	    // 这里写死一个token，你需要在这里取到你设置好的token的值 
	    const token = localStorage.getItem('token');
	    if (token) {
	        // 这里将token设置到headers中，header的key是Authorization，这个key值根据你的需要进行修改即可
	        config.headers.Authorization = "Basic " +window.btoa(token+':'+'') ;
	    }
	    return config
	},
	error => {
	    return Promise.reject(error)
	});


// 用户注册
export const urlRegist = params => { return axios.post(`${baseAuth}/registration`, params); };//`${base}/Regist`
//用户登录 获取token
export const urlLogin = params => {return axios({
  method:'get',
  url:`${base}/token`,
  headers:{'Authorization':params.key}
});};

//订阅接口
export const urlSubscription = params => { return axios.post(`${baseNotLog}/subscription`, params); };
//提交需求工单
export const urlDemand = params => { return axios.post(`${baseNotLog}/demand`, params); };
//消息中心-获取消息
export const urlGetMessages = params => { return axios.get(`${base}/messages`, params); };
//发送密码邮件 请求
export const urlSendEmail = params => { return axios.post(`${baseAuth}/reset_password_request`, params); };
//注册信息验证 请求
export const urlVerification = params => { return axios.get(`${baseAuth}/verification?email=${params.email}&username=${params.username}`, params); };
//重置密码 请求
export const urlResetPwd = params => { return axios.put(`${baseAuth}/reset_password`, params); };
//修改密码 请求
export const urlModifyPwd = params => { return axios.put(`${baseAuth}/modify_password`, params); };
//再次发送 请求
export const urlResendEmail = params => { return axios.post(`${baseAuth}/resend_email`, params); };
//同意协议内容 请求
export const urlAgreement = params => { return axios.put(`${baseAuth}/protocol/agreement`, params); };
//dashboard 请求 获取数据列表
export const urlDashDataList = params => { return axios.get(`${base}/data?page=${params.page}&filter=${params.filter}&owner=${params.owner}`,params); };
//dashboard 请求 获取模板列表
export const urlDashTempList = params => { return axios.get(`${base}/templates?page=${params.page}&filter=${params.filter}&owner=${params.owner}`,params); };
//dashboard 请求 获取模型列表
export const urlDashModelList = params => { return axios.get(`${base}/model?page=${params.page}`,params); };
export const urlDashModelsList = params => { return axios.get(`${base}/models?page=${params.page}&filter=${params.filter}&owner=${params.owner}`,params); };
//dashboard 请求 任务列表
export const urlDashJobList = params => { return axios.get(`${base}/jobs?page=${params.page}&state=${params.state}&sort=${params.sort}`,params); };
//获取数据详情
export const urlDataDetail = params => { return axios.get(`${base}/data/${params.id}`,{ params:params }); };
//购买数据 请求
export const urlBuyData = params => { return axios.post(`${base}/data/purchase`, params); };
//编辑数据 请求
export const urlEditData = params => { return axios.patch(`${base}/data`,params); };
//删除数据请求
export const urldeleteData = params => { return axios.delete(`${base}/data/${params.id}`,params); };
//获得报告详情
//export const urlGetReporter = params => { return axios.get(`${base}/report?report_type=${params.report_type}&id=${params.id}`,params); };
export const urlGetReporter = params => { return axios.get(`${base}/report`,{ params:params }); };
//智能分析请求
export const urlSmartAnalyzation = params => { return axios.post(`${base}/smart_analysis`, params); };
//获得智能分析结果列表请求
export const urlGetSAnalyzation = params => { return axios.get(`${base}/smart_analysis/${params.id}`, params); };
//保存智能建模的结果
export const urlPreservation = params => { return axios.post(`${base}/smart_analysis/preservation`, params); };
//创建模板保存
export const urlSaveTemplate = params => { return axios.post(`${base}/templates`, params); };
//创建模板notebook
export const urlNotebook = params => { return axios.post(`${base}/notebook`, params); };
//创建模板测试
export const urlTestTemplate = params => { return axios.post(`${base}/templates/test`, params); };
//获取模板详情
export const urlTemplateDetail = params => { return axios.get(`${base}/templates/${params.id}`,{ params:params }); };
//购买模板
export const urlBuyTemplate = params => { return axios.post(`${base}/template/purchase`, params); };
//获取模型详情
export const urlModelDetail = params => { return axios.get(`${base}/model?id=${params.id}&type=${params.model_type}`, params); };
//编辑模板
export const urlEditTemplate = params => { return axios.patch(`${base}/templates`,params); };
//获取模板历史任务
export const urlListOfHistoryTemplates = params => { return axios.get(`${base}/templates/${params.id}/jobs/${params.page}`,params); };
//获取分析数据文件内容
//export const urlGetCharacteristic = params => { return axios.get(`${base}/characteristic/${params.id}`,params); };
//手动建模获取源文件
export const urlGetDetail = params => { return axios.get(`${base}/templates/${params.id}`,params); };
//手动建模获取源文件
export const urlUpdateTemplate = params => { return axios.patch(`${base}/templates`,params); };
//创建job
export const urlCreaterJob = params => { return axios.post(`${base}/jobs/creator`,params); };
//运行job
export const urlRunJob = params => { return axios.post(`${base}/jobs/runner`,params); };
//获取用户详情
export const urlGetUserInfo = params => { return axios.get(`${base}/user/${params.username}`,params);};
//编辑用户信息
export const urlEditUserInfo = params => { return axios.patch(`${base}/user`,params);};
